<?php

namespace app\api\controller;

use app\common\controller\Api;
use app\common\model\Mailbox as MailboxModel;
use app\common\library\Ems;
use app\common\library\Sms;
use fast\Random;
use think\Config;
use think\Validate;

/**
 * 信箱接口
 */
class Mailbox extends Api
{
    protected $noNeedLogin = ['anonymity','details'];
    protected $noNeedRight = '*';

    public function _initialize()
    {
        parent::_initialize();

        if (!Config::get('fastadmin.usercenter')) {
            $this->error(__('User center already closed'));
        }

    }

    /**
     * 信箱列表
     */
    public function index()
    {
        $user = $this->auth->getUser();
        $status = $this->request->get('status');
        $page = $this->request->get('page');
        $type='';
        if( $this->request->get('type')){
            $type=$this->request->get('type');
        }
        $list=MailboxModel::getList($user->id,$status,$page,$type);
        $this->success('', $list);
    }
    /**
     * 公开列表
     */
    public function anonymity()
    {

        $status = $this->request->get('status');
        $page = $this->request->get('page');
        $type='';
        if( $this->request->get('type')){
            $type=$this->request->get('type');
        }
        $list=MailboxModel::getAnonymityList($status,$page,$type);
        $this->success('', $list);
    }


    /**
     * 信箱列表
     */
    public function add()
    {
        if ($this->request->isGet()) {
            $user = $this->auth->getUser();
            $this->success('成功');
        }
        $user = $this->auth->getUser();
        $data = $this->request->post();
        $result=MailboxModel::add($data,$user->id);
        if($result)$this->success('提交成功');
        $this->success('提交失败');
    }


    /**
     * 信箱列表
     */
    public function details()
    {

        $data = $this->request->get();
        $result=MailboxModel::details($data['id']);

        $this->success('提交成功',$result);

    }

    /**
     * 信箱列表
     */
    public function mydetails()
    {

        $data = $this->request->get();
        $result=MailboxModel::details($data['id']);
        $user = $this->auth->getUser();
        if($result['user_id']!=$user->id){
            $this->success('此内容匿名数据，您无权查看此内容！');
        }
       $this->success('提交成功',$result);

    }




}
